#include "mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    connect(&close, SIGNAL(clicked()), this, SLOT(close()));
    connect(&but1, SIGNAL(clicked()), this, SLOT(openfile()));
    connect(&spis, SIGNAL(currentIndexChanged(QString)), this, SLOT(write()));
    connect(&save, SIGNAL(clicked()), this, SLOT(saving()));
}

MainWindow::~MainWindow()
{

}
void MainWindow::openfile()
{
    Dr=QFileDialog::getExistingDirectory(this,"Open Directory");
    QDir Dir(Dr);
    QStringList list;
            list<<"*.txt";
    QStringList sl=Dir.entryList(list);
    spis.addItems(sl);
}
void MainWindow::write()
{
    QFile file((Dr+char(92)+spis.currentText()));
    file.open(QIODevice::ReadWrite | QIODevice::Text);
    QTextStream in(&file);
    QString txt;
    text.setText("");
    txt=in.readLine();
    while (txt!="")
    {
        text.append(txt);
        txt=in.readLine();
    }
    file.close();
}
void MainWindow::saving()
{
    QString ab=text.toPlainText();
    QFile file((Dr+char(92)+spis.currentText()));
    file.open(QIODevice::ReadWrite | QIODevice::Text);
    QTextStream out(&file);
    out<<ab;
    file.close();
}
